7 /* private */ var $mId = 0, $mNamespace, $mTitle, $mText;
8 /* private */ var $mTitleWords;
10 function SearchUpdate( $id, $title, $text = false )
12 $nt = Title
::newFromText( $title );
17 $this->mNamespace
= $nt->getNamespace();
18 $this->mTitle
= $nt->getText(); # Discard namespace
20 $this->mTitleWords
= $this->mTextWords
= array();
22 wfDebug( "SearchUpdate object created with invalid title '$title'\n" );
28 global $wgDBminWordLen, $wgLang, $wgDisableSearchUpdate;
30 if( $wgDisableSearchUpdate ||
!$this->mId
) {
33 require_once( 'SearchEngine.php' );
34 $lc = SearchEngine
::legalSearchChars() . "&#;";
35 $db =& wfGetDB( DB_MASTER
);
36 $searchindex = $db->tableName( 'searchindex' );
38 if( $this->mText
== false ) {
39 # Just update the title
40 $lowpri = $db->lowPriorityOption();
41 $sql = "UPDATE $lowpri $searchindex SET si_title='" .
42 $db->strencode( Title
::indexTitle( $this->mNamespace
, $this->mTitle
) ) .
43 "' WHERE si_page={$this->mId}";
44 $db->query( $sql, "SearchUpdate::doUpdate" );
48 # Language-specific strip/conversion
49 $text = $wgLang->stripForSearch( $this->mText
);
51 $text = preg_replace( "/<\\/?\\s*[A-Za-z][A-Za-z0-9]*\\s*([^>]*?)>/",
52 " ", strtolower( " " . $text /*$this->mText*/ . " " ) ); # Strip HTML markup
53 $text = preg_replace( "/(^|\\n)\\s*==\\s+([^\\n]+)\\s+==\\s/sD",
54 "\\2 \\2 \\2 ", $text ); # Emphasize headings
57 $uc = "A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\xA0-\\xFF";
58 $protos = "http|https|ftp|mailto|news|gopher";
59 $pat = "/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
60 $text = preg_replace( $pat, "\\1 \\3", $text );
62 $p1 = "/([^\\[])\\[({$protos}):[{$uc}]+]/";
63 $p2 = "/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
64 $text = preg_replace( $p1, "\\1 ", $text );
65 $text = preg_replace( $p2, "\\1 \\3 ", $text );
67 # Internal image links
68 $pat2 = "/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
69 $text = preg_replace( $pat2, " \\1 \\3", $text );
71 $text = preg_replace( "/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
72 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
74 # Strip all remaining non-search characters
75 $text = preg_replace( "/[^{$lc}]+/", " ", $text );
78 $text = preg_replace( "/([{$lc}]+)'s /", "\\1 \\1's ", $text );
79 $text = preg_replace( "/([{$lc}]+)s' /", "\\1s ", $text );
81 # Strip wiki '' and '''
82 $text = preg_replace( "/''[']*/", " ", $text );
84 $sql = "REPLACE INTO $searchindex (si_page,si_title,si_text) VALUES ({$this->mId},'" .
85 $db->strencode( Title
::indexTitle( $this->mNamespace
, $this->mTitle
) ) . "','" .
86 $db->strencode( $text ) . "')";
87 $db->query( $sql, "SearchUpdate::doUpdate" );